package lsl.leetCode.year2023.test0130;

import java.util.HashMap;

/**
 * description:
 *
 * @author: liushengli
 * data: 2023/1/30
 */
public class test387 {
    public static void main(String[] args) {
        System.out.println(firstUniqChar("aadadaad"));
    }

    public static int firstUniqChar(String str) {
        char[] charArray = str.toCharArray();
        HashMap<Character, Integer> map = new HashMap<>();
        for (char c : charArray) {
            map.put(c, map.getOrDefault(c, 0) + 1);
        }
        for (int i = 0; i < charArray.length; i++) {
            if (map.get(charArray[i]) == 1) {
                return i;
            }
        }
        return -1;
    }
}
